﻿Imports System.Data
Imports VSModel
Imports Cls_Common

Partial Class Control_ToDo_Detail
    Inherits System.Web.UI.UserControl
    Private Shared ReadOnly log As log4net.ILog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
#Region "Sub and Function "
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            If Not Request.QueryString("Id").ToString.Equals("0") Then
                hidID.Value = Request.QueryString("Id")

                LoadListHour(ddlbeHour)
                LoadListHour(ddlDueDateHour)
                LoadListHour(ddlRemindDateHour)

                '  ddleHour.SelectedIndex = 23
                LoadListMinutes(ddlbeMinutes)
                LoadListMinutes(ddlDueDateMinute)
                LoadListMinutes(ddlRemindDateMinute)


                ShowData()
            End If
        End If
    End Sub
    Protected Sub ShowData()
        Using data As New VSEntities
            Dim _UserId As Integer = Session("UserId")
            Dim p As ToDoList = (From q In data.ToDoLists Where q.Id = hidID.Value And q.UserId = _UserId Select q).SingleOrDefault
            If Not p Is Nothing Then
                txtSubject.Text = IIf(IsNothing(p.Subject) = True, "", p.Subject)
                txtDescription.Text = IIf(IsNothing(p.Description) = True, "", p.Description)

                Dim dtStartdate As Date = CType(p.StartDate, Date)
                txtStartdate.Text = dtStartdate.ToString("dd/MM/yyyy")
                ddlbeHour.SelectedValue = dtStartdate.Hour()
                ddlbeMinutes.SelectedValue = dtStartdate.Minute

                Dim dtDuedate As Date = CType(p.DueDate, Date)
                If dtDuedate <> New Date(1900, 1, 1) Then
                    txtDuedate.Text = dtDuedate.ToString("dd/MM/yyyy")
                    ddlDueDateHour.SelectedValue = dtDuedate.Hour()
                    ddlDueDateMinute.SelectedValue = dtDuedate.Minute
                End If

                Dim dtReminddate As Date = CType(p.RemindDate, Date)
                If dtReminddate <> New Date(1900, 1, 1) Then
                    txtReminddate.Text = dtReminddate.ToString("dd/MM/yyyy")
                    ddlRemindDateHour.SelectedValue = dtReminddate.Hour()
                    ddlRemindDateMinute.SelectedValue = dtReminddate.Minute
                End If


                chkIsActive.Checked = p.IsActive
                'txtNumberremind.Text = IIf(IsNothing(p.NumberRemind) = True, "", p.NumberRemind)
                'txtStatus.Text = IIf(IsNothing(p.Status) = True, "", p.Status)
            End If
        End Using
    End Sub
#End Region
#Region "Event for control"



    Sub LoadListHour(ByVal ddlName As DropDownList)
        For i As Integer = 0 To 23
            Dim iTem As New ListItem(i.ToString(), i.ToString())
            ddlName.Items.Add(iTem)
        Next
    End Sub
    Sub LoadListMinutes(ByVal ddlName As DropDownList)
        For i As Integer = 0 To 59
            Dim iTem As New ListItem(i.ToString(), i.ToString())
            ddlName.Items.Add(iTem)
        Next
    End Sub

#End Region
End Class
